/*
 * Proto Streamer
 * Copyright (C) 2009 John Pritchard.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */
package p.s;

import java.io.IOException;
import java.io.PrintStream;

/**
 * Implement this interface or extend {@link Abstract} to create
 * applications.
 * 
 * @see Abstract
 * @see Buffer
 * @see Error
 * @see File
 * @author jdp
 */
public interface Response 
    extends Cloneable, Millis
{

    public final static class Status {
        public final static class Code {
            public final static int Ok = 200;
            public final static int Created = 201;
            public final static int Accepted = 202;
            public final static int NoContent = 204;
            public final static int Moved = 301;
            public final static int Found = 302;
            public final static int NotModified = 304;
            public final static int BadRequest = 400;
            public final static int NotAuthorized = 401;
            public final static int Forbidden = 403;
            public final static int NotFound = 404;
            public final static int LengthRequired = 411;
            public final static int Error = 500;
            public final static int NotImplemented = 501;
            public final static int HttpVersion = 505;
        }
    }


    /**
     * Define response status and headers.
     */
    public void init(Request request)
        throws IOException;
    /**
     * Write response status and headers.
     */
    public void head(Output out)
        throws IOException;
    /**
     * Perform entity body I/O.
     */
    public void tail(Request request, Output out)
        throws IOException;

    /**
     * Copy head for logging.
     */
    public void head(PrintStream out);
    /**
     * @return If written to the client, a valid HTTP message would be
     * produced.
     */
    public boolean isValid();
    /**
     * @return Recycle the connection.  The protocol is defined as
     * "HTTP/1.1" and the Connection header is defined with the value
     * "keep-alive".
     */
    public boolean isConnectionKeepAlive();

}
